package fr.contacts.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import fr.contacts.constant.Constant;
import fr.contacts.controllers.ContactsDAO;

@SessionAttributes({"contact"})
@Controller
public class ContactController {

	@RequestMapping(value = "/contact", method=RequestMethod.GET)
	public String contact(
			@RequestParam("id") int id,
			Model model) {
		
		System.out.println("ContactController: Passing through... ");
		
		model.addAttribute("contact", ContactsDAO.readContact(id));
		
		System.out.println(ContactsDAO.readContact(id));
		System.out.println(ContactsDAO.readAllAdresse(id));
		
		model.addAttribute("adresseList", ContactsDAO.readAllAdresse(id));
		model.addAttribute("errors", Constant.errorList);
		return "/WEB-INF/views/contact.jsp";
		
	}
}
